import { Button, Checkbox, Form, Input } from 'antd';
import axios from '../utils/axios';
import React from 'react';
import {useNavigate} from "react-router-dom"

const Login = () => {
  const navigate = useNavigate()
  const onFinish = (values) => {
      console.log(values);
      axios.get("/api/login",{
        params:values
      }).then(res=>{
         console.log(res.data);
         // 本地存储存登陆状态
         // 本地存储存前端可以访问得路由
         window.localStorage.setItem("token","true")
         window.localStorage.setItem("userpath",JSON.stringify(res.data.routerpath))
         navigate("/home")
      })

  };


  return (
    <Form
      name="basic"
      labelCol={{
        span: 8,
      }}
      wrapperCol={{
        span: 16,
      }}
      initialValues={{
        remember: true,
      }}
      onFinish={onFinish}
      autoComplete="off"
    >
      <Form.Item
        label="Username"
        name="username"
        rules={[
          {
            required: true,
            message: 'Please input your username!',
          },
        ]}
      >
        <Input />
      </Form.Item>

      <Form.Item
        label="Password"
        name="password"
        rules={[
          {
            required: true,
            message: 'Please input your password!',
          },
        ]}
      >
        <Input.Password />
      </Form.Item>

      <Form.Item
        wrapperCol={{
          offset: 8,
          span: 16,
        }}
      >
        <Button type="primary" htmlType="submit">
          登陆
        </Button>
      </Form.Item>
    </Form>
  );
};

export default Login;